﻿@model BskLeague.Models.Team

@{
    ViewBag.Title = "Drużyna - " + @Model.TeamName;
    Func<int, int, int> subtract = (a,b) =>a-b;
}

@if (User.IsInRole("Chef") && Model.ChefPlayer.UserName == User.Identity.Name)
{
    @Html.Partial("~/Views/MyTeam/_Submenu.cshtml")
}

<h2>Szczegóły drużyny</h2>


<table cellspacing="0" cellpadding="0" width="100%">
    <tr>
        <th colspan="3">@Model.TeamName</th>
    </tr>
    <tr>
        <td rowspan="6" width="300px" height="300px">
        @{
            if (@Model.LogoFileName == null)
            {
                @MvcHtmlString.Create("<img src=\"/Content/images/team_logos/default.jpg\" alt=\"Brak Zdjęcia\"/>");
                                                                                                                   
            }
            else
            {
                <text><img src="@Model.LogoFileName" alt="@Model.TeamName"/></text>
            }
        }
        </td>
        <td colspan="2">@Model.Description</td>
    </tr>
    <tr>
        <td>Kapitan drużyny</td>
        <td>@Html.ActionLink(@Model.ChefPlayer.PlayerName + " " + @Model.ChefPlayer.PlayerSurname, "Details/" + @Model.ChefPlayer.PlayerId, "Players")</td>
    </tr>
    <tr>
        <td>Meczy (wygranych/przegranych)</td>
        <td>@(ViewBag.Matches.Won+@ViewBag.Matches.Lost) (@ViewBag.Matches.Won / @ViewBag.Matches.Lost)</td>
    </tr>
    <tr>
        <td>Koszulki 1:</td>
        <td>@Model.TshirtColorPrimary</td>
    </tr>
    <tr>
        <td>Koszulki 2:</td>
        <td>@Model.TshirtColorSecondary</td>
    </tr>
    <tr>
        <td>Lista zawodników</td>
        <td>
            @for (int i = 0; i < @ViewBag.PlayersID.Count; i++)
            {
                @Html.ActionLink((string)@ViewBag.Players[i], "Details/" + (string)@ViewBag.PlayersID[i].ToString(), "Players") <br />
            }

        </td>
    </tr>
</table><br/>

<table cellpadding="0" cellspacing="0" width="100%" style="text-align:center;">
    <tr>
        <td colspan="5">Ostatnie mecze</td>
    </tr>
    <tr>
        <th style="text-align:center;">Runda</th>
        <th style="text-align:center;">Data</th>
        <th style="text-align:center;">Przeciwnik</th>
        <th style="text-align:center;">Wynik</th>
        <th style="text-align:center;">Miejsce spotkania</th>
    </tr>
    @ViewBag.Temp
    @for (int i = 0; i < ViewBag.Date.Count; i++)
    {
        if (@ViewBag.Season[i] != @ViewBag.Temp)
        {<tr>
                <td colspan="5"><b>Sezon @ViewBag.Season[i]</b></td>
                @{ViewBag.Temp = @ViewBag.Season[i];}
            </tr>}
                                                             
        <tr>
            <td>@ViewBag.Round[i]</td>
            <td>@ViewBag.Date[i]</td>
            <td>@Html.ActionLink((string)@ViewBag.Oponent[i], "Details/" + (string)@ViewBag.OponentID[i].ToString(), "Team")</td>
            <td>
                @{string status;
                  if (@ViewBag.TeamPts[i] > @ViewBag.OponentPts[i])
                  { status = "Wygrana (" + @ViewBag.TeamPts[i] + "/" + @ViewBag.OponentPts[i] + ")"; }
                  else if (@ViewBag.TeamPts[i] != @ViewBag.OponentPts[i])
                  { status = "Przegrana (" + @ViewBag.OponentPts[i] + "/" + @ViewBag.TeamPts[i] + ")"; }
                  else
                  { status = "Wynik niepotwierdzony (" + @ViewBag.TeamPts[i] + "/" + @ViewBag.OponentPts[i] + ")"; }
                  /*assuming that a game can't end by the draw, equal number of points stands for a not confirmed match*/
                  }
                @status
            </td>
            <td>@Html.ActionLink((string)@ViewBag.Place[i], "Details/" + (string)@ViewBag.PlaceID[i].ToString(), "Stadium")
            </td>
        </tr>
    }
    @if (@ViewBag.TotalItemsCount > @ViewBag.Take)
    {
        <tr>
            <th colspan=5>
                <center>
                    <
                    @{
        int temp = @ViewBag.TotalItemsCount / @ViewBag.Take;
        temp = ((@ViewBag.TotalItemsCount % @ViewBag.Take) != 0) ? ++temp : temp;
                    }
                    @for (int i = 0; i < temp; i++)
                    {
                        if (@ViewBag.From / @ViewBag.Take == i)
                        {<text>@(i + 1) </text>}
                        else
                        {
                            @Html.ActionLink((i + 1).ToString(),
                                            "Details/",
                                            "Team",
                                            new
                                            {
                                                id = @ViewBag.Id,
                                                from = (i * @ViewBag.Take),
                                                take = @ViewBag.Take
                                            },
                                            null)
                            <text> </text>
                        }
                    }
                    >
                </center>
            </th>
        </tr>
    }
    <tr>
        <td colspan="5" align="center">
            @using (Html.BeginForm("Details", "Team", FormMethod.Get))
            {
                <text>Wyświetl </text>@Html.DropDownList("take", new SelectList(new[]{new KeyValuePair<string, int>("5",5),
                                                        new KeyValuePair<string, int>("7", 7),
                                                        new KeyValuePair<string, int>("10", 10)},
                                                        "Value", "Key"));
                <text>pozycji na stronie.</text>                                          
                <input type="submit" value="Zatwierdź" />
            }
        </td>
    </tr>

</table>